From 660f0898807dae6236128f1db2a8ae8cc90ae247 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 27 Apr 2006 18:50:39 +0000 Subject: [PATCH] Improve positioning of the menu when popped up by keynav. (#334987, 2006-04-27 Matthias Clasen * gtk/gtkentry.c (popup_position_func): Improve positioning of the menu when popped up by keynav. (#334987, Christian Persch) --- ChangeLog | 4 ++++ ChangeLog.pre-2-10 | 4 ++++ gtk/gtkentry.c | 41 +++++++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2dec19909..a7d5d0d42d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-04-27 Matthias Clasen + * gtk/gtkentry.c (popup_position_func): Improve positioning + of the menu when popped up by keynav. (#334987, Christian + Persch) + * gtk/gtkdnd.c (gtk_drag_set_icon_window): Handle the case of being called after the drag is cancelled. (#339224, Benjamin Otte) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index b2dec19909..a7d5d0d42d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,9 @@ 2006-04-27 Matthias Clasen + * gtk/gtkentry.c (popup_position_func): Improve positioning + of the menu when popped up by keynav. (#334987, Christian + Persch) + * gtk/gtkdnd.c (gtk_drag_set_icon_window): Handle the case of being called after the drag is cancelled. (#339224, Benjamin Otte) diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 2426c2a1a2..2cf8f01609 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -4828,31 +4828,44 @@ popup_position_func (GtkMenu *menu, { GtkEntry *entry = GTK_ENTRY (user_data); GtkWidget *widget = GTK_WIDGET (entry); - GdkScreen *screen = gtk_widget_get_screen (widget); - GtkRequisition req; - gint monitor_num; + GdkScreen *screen; + GtkRequisition menu_req; GdkRectangle monitor; - + GtkBorder inner_border; + gint monitor_num, strong_x, height; + g_return_if_fail (GTK_WIDGET_REALIZED (entry)); - gdk_window_get_origin (widget->window, x, y); - - gtk_widget_size_request (entry->popup_menu, &req); - - *x += widget->allocation.width / 2; - *y += widget->allocation.height; + gdk_window_get_origin (entry->text_area, x, y); - monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); + screen = gtk_widget_get_screen (widget); + monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area); + if (monitor_num < 0) + monitor_num = 0; gtk_menu_set_monitor (menu, monitor_num); + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + gtk_widget_size_request (entry->popup_menu, &menu_req); + gdk_drawable_get_size (entry->text_area, NULL, &height); + gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL); + get_inner_border (entry, &inner_border); + + *x += inner_border.left + strong_x - entry->scroll_offset; + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + *x -= menu_req.width; - *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width)); - *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height)); + if ((*y + height + menu_req.height) <= monitor.y + monitor.height) + *y += height; + else if ((*y - menu_req.height) >= monitor.y) + *y -= menu_req.height; + else if (monitor.y + monitor.height - (*y + height) > *y) + *y += height; + else + *y -= menu_req.height; *push_in = FALSE; } - static void unichar_chosen_func (const char *text, gpointer data) -- 2.30.2